<!DOCTYPE html>
<html>
<head>
    <title>门诊查询--中软高科-2015</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../Css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="../Css/style.css" />
    <script type="text/javascript" src="../Js/jquery.js"></script>
    <script type="text/javascript" src="../Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../Js/bootstrap.js"></script>
    <script type="text/javascript" src="../Js/ckform.js"></script>
    <script type="text/javascript" src="../Js/common.js"></script>

    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }
        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>

</head>
<body>

<form id="selectForm" class="definewidth m20">
<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <td width="10%" class="tableleft">病历号：</td>
        <td><input type="text" name="id" value=""/></td>

        <td width="10%" class="tableleft">病人姓名：</td>
        <td><input type="text" name="registerName" value=""/></td>

        <td width="10%" class="tableleft">科室：</td>
        <td><input type="text" name="deptName" value=""/></td>
    </tr>
    <tr>

        <td width="10%" class="tableleft">挂号时间：</td>
        <td colspan="5">
            <input type="date" name="star" id="star" value=""/>&nbsp;至&nbsp;
            <input type="date" name="end" id="end" value=""/>
            <button type="button" class="btn btn-primary" onclick="loadData()">查询</button>
            <button type="submit" class="btn btn-primary" type="button">清空</button>

        </td>
    </tr>
</table>
</form>

<table class="table table-bordered table-hover definewidth m10" >
   <thead>
    <tr>
        <th><input type="checkbox" id="checkall" onChange="checkall();"></th>
        <th>门诊编号</th>
        <th>病人姓名</th>
        <th>挂号时间</th>
        <th>挂号科室</th>
        <th>状态</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody id="tbody">
    </tbody>
  </table>

<table class="table table-bordered table-hover definewidth m10">
    <tr>
        <th colspan="5">
            <div class="pull-left">
                <button type="button" class="btn btn-success" id="newNav">挂号</button>&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-success" onclick="blackRegisters();">退号</button>&nbsp;&nbsp;&nbsp;
                <button type="button" class="btn btn-success" onclick="exportInfo()">导出Excel</button>
            </div>
            <div class="inline pull-right page">
                <a name="" id="firstPage" onclick="A()">第一页</a>
                <a name="" id="prePage" onclick="B()">上一页</a>
                <span id="currentPage"></span>
                <a name="" id="nextPage" onclick="C()">下一页</a>
                <a name="" id="lastPage" onclick="D()">最后一页</a>
                &nbsp;&nbsp;&nbsp;共<span id="total" class='current'></span>条记录
                <span id="pageNum"></span>/<span id="pages"></span>页
                <span id="pageSize" class="hidden"></span>
            </div>
        </th>
    </tr>
</table>

<script type="text/javascript">
    loadData();
    function A() {
        if ($("#firstPage").attr("class") == "btn btn-small disabled") {
            return;
        }
        let num = $("#firstPage").attr("name");
        $("#pageNum").html(num);
        loadData();
    };
    function B() {
        if ($("#prePage").attr("class") == "btn btn-small disabled") {
            return;
        }
        let num = $("#prePage").attr("name");
        $("#pageNum").html(num);
        loadData();
    };
    function C() {
        if ($("#nextPage").attr("class") == "btn btn-small disabled") {
            return;
        }
        let num = $("#nextPage").attr("name");
        $("#pageNum").html(num);
        loadData();
    };
    function D() {
        if ($("#lastPage").attr("class") == "btn btn-small disabled") {
            return;
        }
        let num = $("#lastPage").attr("name");
        $("#pageNum").html(num);
        loadData();
    };
    function E(j) {
        $("#pageNum").html(j);
        loadData();
    };
    function fillPageData(pageInfo) {
        //填充信息
        $("#total").html(pageInfo.total);
        $("#pages").html(pageInfo.pages);
        $("#pageNum").html(pageInfo.pageNum);
        $("#pageSize").html(pageInfo.pageSize);
        let str = "";
        for (let i = 1; i <= pageInfo.pages; i++) {
            str += '<a onclick=E(' + i + ')>' + i + '</a>';
        }
        $("#currentPage").html(str);

        //设置按钮的属性值和样式
        $("#firstPage").attr("name", 1);
        $("#prePage").attr("name", pageInfo.prePage);
        $("#nextPage").attr("name", pageInfo.nextPage);
        $("#lastPage").attr("name", pageInfo.pages);
        $("#firstPage").removeClass("btn btn-small disabled");
        $("#prePage").removeClass("btn btn-small disabled");
        $("#nextPage").removeClass("btn btn-small disabled");
        $("#lastPage").removeClass("btn btn-small disabled");
        if (pageInfo.isFirstPage) {//如果是第一页：上一页和首页禁用
            $("#firstPage").addClass("btn btn-small disabled");
            $("#prePage").addClass("btn btn-small disabled");
            $("#current1").addClass("btn btn-small disabled");
        }
        if (pageInfo.isLastPage) {//如果已经是最后一页：下一页和末页禁用
            $("#nextPage").addClass("btn btn-small disabled");
            $("#lastPage").addClass("btn btn-small disabled");
        }
    }

    //获取科室名
    function getDeptByid(department) {
        var deptName="无科室";
        $.ajax({
            url:"/dept/getDeptById?id="+department,
            type:"GET",
            async : false,
            success:function (vo) {
                if(vo.obj!=null){
                    deptName = vo.obj.deptName;
                }
            }
        });
        return deptName;
    }

    function loadData() {
        let pageNum = $("#pageNum").html();
        let pageSize = $("#pageSize").html();
        $.ajax({
            url: "/register/getRegisters?pageNum="+pageNum+"&pageSize="+pageSize,
            type: 'POST',
            data: $("#selectFrom").serialize(),
            dataType: 'json',
            success: function (vo) {
                let str = "";
                let btnStr = "";
                let data = vo.pageInfo.list;
                for (let i = 0; i < data.length; i++) {
                    let id = data[i].id;
                    let registerName = data[i].registerName;
                    let registerDate = data[i].registerDate;
                    let department =data[i].department;
                    let deptName = getDeptByid(department);
                    let ss=data[i].status;
                    var status = "已退号";
                    if (data[i].status == -1) {
                        btnStr = "null";
                    } else {
                        btnStr = '<a href="look.html?id=' + id + '">详情>></a>&nbsp;&nbsp;&nbsp;\n' +
                            '<a href="edit.html?id=' + id + '">更改</a>&nbsp;&nbsp;&nbsp;\n' +
                            "<a onclick=blackRegister("+ id +")>退号</a>"
                    }
                    if(ss==1){
                        status="以住院";
                    }
                    if(ss==0){
                        status="以挂号";
                    }
                    str += '<tr>' +
                        '        <td style="vertical-align:middle;"><input type="checkbox" name="check" value='+ id +'></td>' +
                        '        <td style="vertical-align:middle;">' + id + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + registerName + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + registerDate + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + deptName + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + status + '</td>\n' +
                        '        <td style="vertical-align:middle;">' + btnStr + '</td>\n' +
                        '    </tr>'
                }
                $("#tbody").html(str);
                fillPageData(vo.pageInfo);
            }
        })
    }

    function checkall(){
        var alls=document.getElementsByName("check");
        var ch=document.getElementById("checkall");
        if(ch.checked){
            for(var i=0;i<alls.length;i++){
                alls[i].checked=true;
            }
        }else{
            for(var i=0;i<alls.length;i++){
                alls[i].checked=false;
            }
        }
    }

    //退号单个
    function blackRegister(id){
        $.ajax({
            url: "/register/blackRegister",
            type: 'GET',
            data: {
                "ids":id
            },
            traditional:true,
            dataType: 'json',
            success: function (vo) {
                alert(vo.msg);
                loadData();
            }
        })
    }

    //退号多个按钮
    function blackRegisters() {
        let alls = document.getElementsByName("check");
        let ids = new Array();
        for (let i = 0; i < alls.length; i++) {
            if (alls[i].checked) {
                ids.push(alls[i].value);
            }
        }
        if (ids.length > 0) {
            $.ajax({
                url: "/register/blackRegister",
                type: 'GET',
                data: {
                    "ids":ids
                },
                traditional:true,
                dataType: 'json',
                success: function (vo) {
                    alert(vo.msg);
                    loadData();
                }
            })
        } else {
            alert("请选中要操作的项");
        }
    }

    function exportInfo() {
        window.location.href="exportExcel.html";
    }

    $(function () {
        $('#newNav').click(function(){
            window.location.href="add.html";
        });
    });

</script>
</body>
</html>
